<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>OJ多组和单组输入输出 | whoway</title>
    <meta name="description" content="Personal Blog Website">
    <link rel="icon" href="/images/photo.jpg">
  <link rel="manifest" href="/images/photo.jpg">
  <link rel="apple-touch-icon" href="/images/photo.jpg">
  <meta http-quiv="pragma" cotent="no-cache">
  <meta http-quiv="pragma" cotent="no-cache,must-revalidate">
  <meta http-quiv="expires" cotent="0">
    
    <link rel="preload" href="/assets/css/0.styles.0dbae9ec.css" as="style"><link rel="preload" href="/assets/js/app.c70e21ad.js" as="script"><link rel="preload" href="/assets/js/56.62ac9b92.js" as="script"><link rel="prefetch" href="/assets/js/10.15222a53.js"><link rel="prefetch" href="/assets/js/100.7e0e5a86.js"><link rel="prefetch" href="/assets/js/101.efd59f25.js"><link rel="prefetch" href="/assets/js/102.dfbdc06c.js"><link rel="prefetch" href="/assets/js/103.d3ab2109.js"><link rel="prefetch" href="/assets/js/104.117957ef.js"><link rel="prefetch" href="/assets/js/105.046e8ff3.js"><link rel="prefetch" href="/assets/js/106.aebdc17d.js"><link rel="prefetch" href="/assets/js/107.248733c2.js"><link rel="prefetch" href="/assets/js/108.a2fecadc.js"><link rel="prefetch" href="/assets/js/109.35196857.js"><link rel="prefetch" href="/assets/js/11.770642f2.js"><link rel="prefetch" href="/assets/js/110.cf3d973c.js"><link rel="prefetch" href="/assets/js/111.f985889a.js"><link rel="prefetch" href="/assets/js/112.ad614f41.js"><link rel="prefetch" href="/assets/js/113.f666653c.js"><link rel="prefetch" href="/assets/js/114.c6c3f384.js"><link rel="prefetch" href="/assets/js/115.e51d3c2f.js"><link rel="prefetch" href="/assets/js/116.4f4b39f5.js"><link rel="prefetch" href="/assets/js/117.99352e11.js"><link rel="prefetch" href="/assets/js/118.c6ae6572.js"><link rel="prefetch" href="/assets/js/119.4ccbe778.js"><link rel="prefetch" href="/assets/js/12.042a92ff.js"><link rel="prefetch" href="/assets/js/120.edda1c4f.js"><link rel="prefetch" href="/assets/js/121.30a638ed.js"><link rel="prefetch" href="/assets/js/122.6efcefb1.js"><link rel="prefetch" href="/assets/js/123.91e6665b.js"><link rel="prefetch" href="/assets/js/124.f27e3d7e.js"><link rel="prefetch" href="/assets/js/125.c75712d5.js"><link rel="prefetch" href="/assets/js/126.ed756cce.js"><link rel="prefetch" href="/assets/js/127.2f06c74c.js"><link rel="prefetch" href="/assets/js/128.d5f6f30e.js"><link rel="prefetch" href="/assets/js/129.508b7eed.js"><link rel="prefetch" href="/assets/js/13.b5280c37.js"><link rel="prefetch" href="/assets/js/130.dc05f9aa.js"><link rel="prefetch" href="/assets/js/131.e0ba69b1.js"><link rel="prefetch" href="/assets/js/132.d79bcaa4.js"><link rel="prefetch" href="/assets/js/133.34acc01a.js"><link rel="prefetch" href="/assets/js/134.dabf64d5.js"><link rel="prefetch" href="/assets/js/135.ad90c915.js"><link rel="prefetch" href="/assets/js/136.dbb0074f.js"><link rel="prefetch" href="/assets/js/137.284ad365.js"><link rel="prefetch" href="/assets/js/138.a4b6856f.js"><link rel="prefetch" href="/assets/js/139.c9c1e20f.js"><link rel="prefetch" href="/assets/js/14.df02ba38.js"><link rel="prefetch" href="/assets/js/140.8b0a9269.js"><link rel="prefetch" href="/assets/js/141.9c7759c5.js"><link rel="prefetch" href="/assets/js/142.a4201a82.js"><link rel="prefetch" href="/assets/js/143.d7da6e8c.js"><link rel="prefetch" href="/assets/js/144.5e48e65d.js"><link rel="prefetch" href="/assets/js/145.a0e2633c.js"><link rel="prefetch" href="/assets/js/146.3c775f9b.js"><link rel="prefetch" href="/assets/js/147.22add89a.js"><link rel="prefetch" href="/assets/js/148.cfde1009.js"><link rel="prefetch" href="/assets/js/149.ffc835b5.js"><link rel="prefetch" href="/assets/js/15.fbdfc4ee.js"><link rel="prefetch" href="/assets/js/150.406c4b20.js"><link rel="prefetch" href="/assets/js/151.b2040eea.js"><link rel="prefetch" href="/assets/js/152.7bc65661.js"><link rel="prefetch" href="/assets/js/153.1d7c65e3.js"><link rel="prefetch" href="/assets/js/154.1309de49.js"><link rel="prefetch" href="/assets/js/155.81d3ee1f.js"><link rel="prefetch" href="/assets/js/156.154a4ef2.js"><link rel="prefetch" href="/assets/js/16.e5eb6147.js"><link rel="prefetch" href="/assets/js/17.57853c4a.js"><link rel="prefetch" href="/assets/js/18.cb9d7518.js"><link rel="prefetch" href="/assets/js/19.f354dc47.js"><link rel="prefetch" href="/assets/js/2.570d8a23.js"><link rel="prefetch" href="/assets/js/20.b5af7fad.js"><link rel="prefetch" href="/assets/js/21.0b1928fe.js"><link rel="prefetch" href="/assets/js/22.f78666de.js"><link rel="prefetch" href="/assets/js/23.29c3f366.js"><link rel="prefetch" href="/assets/js/24.6f596516.js"><link rel="prefetch" href="/assets/js/25.14067b60.js"><link rel="prefetch" href="/assets/js/26.74ba4989.js"><link rel="prefetch" href="/assets/js/27.13d60edd.js"><link rel="prefetch" href="/assets/js/28.9523cb32.js"><link rel="prefetch" href="/assets/js/29.8ec842e9.js"><link rel="prefetch" href="/assets/js/3.3fb3d2e0.js"><link rel="prefetch" href="/assets/js/30.805597a8.js"><link rel="prefetch" href="/assets/js/31.831b195d.js"><link rel="prefetch" href="/assets/js/32.063c672d.js"><link rel="prefetch" href="/assets/js/33.6d93fac3.js"><link rel="prefetch" href="/assets/js/34.56e8263c.js"><link rel="prefetch" href="/assets/js/35.dbe688bb.js"><link rel="prefetch" href="/assets/js/36.dc5af2c1.js"><link rel="prefetch" href="/assets/js/37.0a7494f6.js"><link rel="prefetch" href="/assets/js/38.fe4fc171.js"><link rel="prefetch" href="/assets/js/39.f5ed5e92.js"><link rel="prefetch" href="/assets/js/4.2c405ec8.js"><link rel="prefetch" href="/assets/js/40.fe7e2714.js"><link rel="prefetch" href="/assets/js/41.30b0811d.js"><link rel="prefetch" href="/assets/js/42.76f52d62.js"><link rel="prefetch" href="/assets/js/43.e7bb0817.js"><link rel="prefetch" href="/assets/js/44.ead0e883.js"><link rel="prefetch" href="/assets/js/45.235df046.js"><link rel="prefetch" href="/assets/js/46.5f09e829.js"><link rel="prefetch" href="/assets/js/47.67116354.js"><link rel="prefetch" href="/assets/js/48.31f34543.js"><link rel="prefetch" href="/assets/js/49.10b5ebba.js"><link rel="prefetch" href="/assets/js/5.6f47322c.js"><link rel="prefetch" href="/assets/js/50.c0f0b7f1.js"><link rel="prefetch" href="/assets/js/51.5143f3bf.js"><link rel="prefetch" href="/assets/js/52.eeddfd48.js"><link rel="prefetch" href="/assets/js/53.eb790db5.js"><link rel="prefetch" href="/assets/js/54.8fe5421c.js"><link rel="prefetch" href="/assets/js/55.d8f9004b.js"><link rel="prefetch" href="/assets/js/57.a9caec0d.js"><link rel="prefetch" href="/assets/js/58.f93fc522.js"><link rel="prefetch" href="/assets/js/59.a81a03aa.js"><link rel="prefetch" href="/assets/js/6.8c2ea393.js"><link rel="prefetch" href="/assets/js/60.ab782775.js"><link rel="prefetch" href="/assets/js/61.6dd12daf.js"><link rel="prefetch" href="/assets/js/62.76f4b01f.js"><link rel="prefetch" href="/assets/js/63.6f8a4742.js"><link rel="prefetch" href="/assets/js/64.6f8bb1fa.js"><link rel="prefetch" href="/assets/js/65.4120a44b.js"><link rel="prefetch" href="/assets/js/66.360c2d2b.js"><link rel="prefetch" href="/assets/js/67.26f84d32.js"><link rel="prefetch" href="/assets/js/68.68f45e5e.js"><link rel="prefetch" href="/assets/js/69.e311eb56.js"><link rel="prefetch" href="/assets/js/7.6762b2d7.js"><link rel="prefetch" href="/assets/js/70.cea82674.js"><link rel="prefetch" href="/assets/js/71.783ddcf7.js"><link rel="prefetch" href="/assets/js/72.e5467385.js"><link rel="prefetch" href="/assets/js/73.b8fb681b.js"><link rel="prefetch" href="/assets/js/74.1bae37db.js"><link rel="prefetch" href="/assets/js/75.024387e5.js"><link rel="prefetch" href="/assets/js/76.a8e53010.js"><link rel="prefetch" href="/assets/js/77.8c55500a.js"><link rel="prefetch" href="/assets/js/78.7ce90bf5.js"><link rel="prefetch" href="/assets/js/79.ef71713f.js"><link rel="prefetch" href="/assets/js/8.788a6364.js"><link rel="prefetch" href="/assets/js/80.acad589d.js"><link rel="prefetch" href="/assets/js/81.02670d10.js"><link rel="prefetch" href="/assets/js/82.53b7b1ac.js"><link rel="prefetch" href="/assets/js/83.99eb8581.js"><link rel="prefetch" href="/assets/js/84.d1535ce3.js"><link rel="prefetch" href="/assets/js/85.fe2b7de9.js"><link rel="prefetch" href="/assets/js/86.41850272.js"><link rel="prefetch" href="/assets/js/87.1cdc6df9.js"><link rel="prefetch" href="/assets/js/88.01bf3461.js"><link rel="prefetch" href="/assets/js/89.17c69819.js"><link rel="prefetch" href="/assets/js/9.3813842d.js"><link rel="prefetch" href="/assets/js/90.f6ae7e35.js"><link rel="prefetch" href="/assets/js/91.507bc284.js"><link rel="prefetch" href="/assets/js/92.90551782.js"><link rel="prefetch" href="/assets/js/93.dc442d78.js"><link rel="prefetch" href="/assets/js/94.315f4e94.js"><link rel="prefetch" href="/assets/js/95.ccd6c6bf.js"><link rel="prefetch" href="/assets/js/96.0c6d89d0.js"><link rel="prefetch" href="/assets/js/97.1a9f10a9.js"><link rel="prefetch" href="/assets/js/98.43be3caa.js"><link rel="prefetch" href="/assets/js/99.54c8207b.js">
    <link rel="stylesheet" href="/assets/css/0.styles.0dbae9ec.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><!----> <span class="site-name">whoway</span></a> <div class="links" style="max-width:nullpx;"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">🎓Coding</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/00.Coding/TheBeautyOfProgramming/" class="nav-link">🔖编程之美题解</a></li><li class="dropdown-item"><!----> <a href="/00.Coding/CodeWarehouse/" class="nav-link">🔖代码意识流</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">🚀语言</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/01.Language/Overview/" class="nav-link">🔖概述</a></li><li class="dropdown-item"><!----> <a href="/01.Language/C/" class="nav-link">⭐️C</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Cpp/" class="nav-link">🚀C++</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Java/" class="nav-link">☕️Java</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Python/" class="nav-link">🧩Python3</a></li></ul></div></div><div class="nav-item"><a href="/02.Hardware/" class="nav-link">✔️硬件基础</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">⭐️软件基础</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/03.Software/01.DataStructureAndAlgorithm/" class="nav-link router-link-active">🐾数据结构和算法</a></li><li class="dropdown-item"><!----> <a href="/03.Software/02.OS/" class="nav-link">💻操作系统</a></li><li class="dropdown-item"><!----> <a href="/03.Software/03.Net/" class="nav-link">☁️计算机网络</a></li><li class="dropdown-item"><!----> <a href="/03.Software/04.SE/" class="nav-link">✅软件工程</a></li></ul></div></div><div class="nav-item"><a href="/04.Database/" class="nav-link">🎨数据库</a></div><div class="nav-item"><a href="/05.Engineer/" class="nav-link">🔖学术/工程</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">⚙️工具</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/06.Tools/01.employment/" class="nav-link">🔖求职</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/02.efficiency/" class="nav-link">🚀效能</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/03.windows/" class="nav-link">⚙️Windows</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/04.design/" class="nav-link">🧩设计</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/05.linux/" class="nav-link">🐉Linux</a></li></ul></div></div><div class="nav-item"><a href="https://github.com/whoway" target="_blank" rel="noopener noreferrer" class="nav-link external">
  GitHub
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <div class="sidebar"><nav class="nav-links"><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">🎓Coding</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/00.Coding/TheBeautyOfProgramming/" class="nav-link">🔖编程之美题解</a></li><li class="dropdown-item"><!----> <a href="/00.Coding/CodeWarehouse/" class="nav-link">🔖代码意识流</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">🚀语言</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/01.Language/Overview/" class="nav-link">🔖概述</a></li><li class="dropdown-item"><!----> <a href="/01.Language/C/" class="nav-link">⭐️C</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Cpp/" class="nav-link">🚀C++</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Java/" class="nav-link">☕️Java</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Python/" class="nav-link">🧩Python3</a></li></ul></div></div><div class="nav-item"><a href="/02.Hardware/" class="nav-link">✔️硬件基础</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">⭐️软件基础</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/03.Software/01.DataStructureAndAlgorithm/" class="nav-link router-link-active">🐾数据结构和算法</a></li><li class="dropdown-item"><!----> <a href="/03.Software/02.OS/" class="nav-link">💻操作系统</a></li><li class="dropdown-item"><!----> <a href="/03.Software/03.Net/" class="nav-link">☁️计算机网络</a></li><li class="dropdown-item"><!----> <a href="/03.Software/04.SE/" class="nav-link">✅软件工程</a></li></ul></div></div><div class="nav-item"><a href="/04.Database/" class="nav-link">🎨数据库</a></div><div class="nav-item"><a href="/05.Engineer/" class="nav-link">🔖学术/工程</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">⚙️工具</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/06.Tools/01.employment/" class="nav-link">🔖求职</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/02.efficiency/" class="nav-link">🚀效能</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/03.windows/" class="nav-link">⚙️Windows</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/04.design/" class="nav-link">🧩设计</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/05.linux/" class="nav-link">🐉Linux</a></li></ul></div></div><div class="nav-item"><a href="https://github.com/whoway" target="_blank" rel="noopener noreferrer" class="nav-link external">
  GitHub
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div> <!----></nav>  <ul class="sidebar-links"><li><div class="sidebar-group first"><p class="sidebar-heading open"><span>OJ多组和单组输入输出</span> <!----></p> <ul class="sidebar-group-items"><li><a href="/03.Software/01.DataStructureAndAlgorithm/Part01.OJ%E5%A4%9A%E7%BB%84%E8%BE%93%E5%85%A5%E8%BE%93%E5%87%BA.html#📑-目录" class="sidebar-link">📑 目录</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/03.Software/01.DataStructureAndAlgorithm/Part01.OJ%E5%A4%9A%E7%BB%84%E8%BE%93%E5%85%A5%E8%BE%93%E5%87%BA.html#_01-oj中多组和单组输入输出" class="sidebar-link">01.OJ中多组和单组输入输出</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/03.Software/01.DataStructureAndAlgorithm/Part01.OJ%E5%A4%9A%E7%BB%84%E8%BE%93%E5%85%A5%E8%BE%93%E5%87%BA.html#_1-1-循环i-o处理faq" class="sidebar-link">1.1.循环I/O处理FAQ</a></li><li class="sidebar-sub-header"><a href="/03.Software/01.DataStructureAndAlgorithm/Part01.OJ%E5%A4%9A%E7%BB%84%E8%BE%93%E5%85%A5%E8%BE%93%E5%87%BA.html#_1-2-常见语法" class="sidebar-link">1.2.常见语法</a></li><li class="sidebar-sub-header"><a href="/03.Software/01.DataStructureAndAlgorithm/Part01.OJ%E5%A4%9A%E7%BB%84%E8%BE%93%E5%85%A5%E8%BE%93%E5%87%BA.html#_1-3-笔试题技巧✔️" class="sidebar-link">1.3.笔试题技巧✔️</a></li><li class="sidebar-sub-header"><a href="/03.Software/01.DataStructureAndAlgorithm/Part01.OJ%E5%A4%9A%E7%BB%84%E8%BE%93%E5%85%A5%E8%BE%93%E5%87%BA.html#_1-4-多组输入输出的坑" class="sidebar-link">1.4.多组输入输出的坑</a></li><li class="sidebar-sub-header"><a href="/03.Software/01.DataStructureAndAlgorithm/Part01.OJ%E5%A4%9A%E7%BB%84%E8%BE%93%E5%85%A5%E8%BE%93%E5%87%BA.html#_1-5-关于输出格式的坑" class="sidebar-link">1.5.关于输出格式的坑</a></li></ul></li><li><a href="/03.Software/01.DataStructureAndAlgorithm/Part01.OJ%E5%A4%9A%E7%BB%84%E8%BE%93%E5%85%A5%E8%BE%93%E5%87%BA.html#_02-『多组输入输出』oj使用经验" class="sidebar-link">02.『多组输入输出』OJ使用经验</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/03.Software/01.DataStructureAndAlgorithm/Part01.OJ%E5%A4%9A%E7%BB%84%E8%BE%93%E5%85%A5%E8%BE%93%E5%87%BA.html#_2-1-如何搞定超时？估计需要的算法时间复杂度✔️" class="sidebar-link">2.1.如何搞定超时？估计需要的算法时间复杂度✔️</a></li><li class="sidebar-sub-header"><a href="/03.Software/01.DataStructureAndAlgorithm/Part01.OJ%E5%A4%9A%E7%BB%84%E8%BE%93%E5%85%A5%E8%BE%93%E5%87%BA.html#_2-2-常见边界数据" class="sidebar-link">2.2.常见边界数据</a></li><li class="sidebar-sub-header"><a href="/03.Software/01.DataStructureAndAlgorithm/Part01.OJ%E5%A4%9A%E7%BB%84%E8%BE%93%E5%85%A5%E8%BE%93%E5%87%BA.html#_2-3-什么叫特判『special-judge』✔️" class="sidebar-link">2.3.什么叫特判『Special judge』✔️</a></li><li class="sidebar-sub-header"><a href="/03.Software/01.DataStructureAndAlgorithm/Part01.OJ%E5%A4%9A%E7%BB%84%E8%BE%93%E5%85%A5%E8%BE%93%E5%87%BA.html#_2-4-『多组输出输出』常见坑：防踩坑" class="sidebar-link">2.4.『多组输出输出』常见坑：防踩坑</a></li><li class="sidebar-sub-header"><a href="/03.Software/01.DataStructureAndAlgorithm/Part01.OJ%E5%A4%9A%E7%BB%84%E8%BE%93%E5%85%A5%E8%BE%93%E5%87%BA.html#_2-5-『训练』牛客多组i-o" class="sidebar-link">2.5.『训练』牛客多组I/O</a></li><li class="sidebar-sub-header"><a href="/03.Software/01.DataStructureAndAlgorithm/Part01.OJ%E5%A4%9A%E7%BB%84%E8%BE%93%E5%85%A5%E8%BE%93%E5%87%BA.html#_2-6-mle" class="sidebar-link">2.6.MLE</a></li><li class="sidebar-sub-header"><a href="/03.Software/01.DataStructureAndAlgorithm/Part01.OJ%E5%A4%9A%E7%BB%84%E8%BE%93%E5%85%A5%E8%BE%93%E5%87%BA.html#_2-7-关于cin的速度" class="sidebar-link">2.7.关于cin的速度</a></li></ul></li><li><a href="/03.Software/01.DataStructureAndAlgorithm/Part01.OJ%E5%A4%9A%E7%BB%84%E8%BE%93%E5%85%A5%E8%BE%93%E5%87%BA.html#_03-c和c-混合i-o难点辨析" class="sidebar-link">03.C和C++混合I/O难点辨析</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/03.Software/01.DataStructureAndAlgorithm/Part01.OJ%E5%A4%9A%E7%BB%84%E8%BE%93%E5%85%A5%E8%BE%93%E5%87%BA.html#_3-1-辨析单引号和双引号" class="sidebar-link">3.1.辨析单引号和双引号</a></li><li class="sidebar-sub-header"><a href="/03.Software/01.DataStructureAndAlgorithm/Part01.OJ%E5%A4%9A%E7%BB%84%E8%BE%93%E5%85%A5%E8%BE%93%E5%87%BA.html#_3-2-常见数字格式—输入输出" class="sidebar-link">3.2.常见数字格式—输入输出</a></li><li class="sidebar-sub-header"><a href="/03.Software/01.DataStructureAndAlgorithm/Part01.OJ%E5%A4%9A%E7%BB%84%E8%BE%93%E5%85%A5%E8%BE%93%E5%87%BA.html#_3-3-字符串输入输出" class="sidebar-link">3.3.字符串输入输出</a></li><li class="sidebar-sub-header"><a href="/03.Software/01.DataStructureAndAlgorithm/Part01.OJ%E5%A4%9A%E7%BB%84%E8%BE%93%E5%85%A5%E8%BE%93%E5%87%BA.html#_3-4-用2种方法解决gets被禁用✔️" class="sidebar-link">3.4.用2种方法解决gets被禁用✔️</a></li><li class="sidebar-sub-header"><a href="/03.Software/01.DataStructureAndAlgorithm/Part01.OJ%E5%A4%9A%E7%BB%84%E8%BE%93%E5%85%A5%E8%BE%93%E5%87%BA.html#问题引入：pat编译器上的坑" class="sidebar-link">问题引入：PAT编译器上的坑</a></li><li class="sidebar-sub-header"><a href="/03.Software/01.DataStructureAndAlgorithm/Part01.OJ%E5%A4%9A%E7%BB%84%E8%BE%93%E5%85%A5%E8%BE%93%E5%87%BA.html#方案1：getline-cin-first-✔️" class="sidebar-link">方案1：getline(cin, first);✔️</a></li><li class="sidebar-sub-header"><a href="/03.Software/01.DataStructureAndAlgorithm/Part01.OJ%E5%A4%9A%E7%BB%84%E8%BE%93%E5%85%A5%E8%BE%93%E5%87%BA.html#方案2：cin-getline✔️" class="sidebar-link">方案2：cin.getline✔️</a></li></ul></li><li><a href="/03.Software/01.DataStructureAndAlgorithm/Part01.OJ%E5%A4%9A%E7%BB%84%E8%BE%93%E5%85%A5%E8%BE%93%E5%87%BA.html#_04-oj多组输入输出『分语言』" class="sidebar-link">04.OJ多组输入输出『分语言』</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/03.Software/01.DataStructureAndAlgorithm/Part01.OJ%E5%A4%9A%E7%BB%84%E8%BE%93%E5%85%A5%E8%BE%93%E5%87%BA.html#_4-1-纯c-语言版（不准用c语言版本）" class="sidebar-link">4.1.纯C++语言版（不准用C语言版本）</a></li><li class="sidebar-sub-header"><a href="/03.Software/01.DataStructureAndAlgorithm/Part01.OJ%E5%A4%9A%E7%BB%84%E8%BE%93%E5%85%A5%E8%BE%93%E5%87%BA.html#_4-2-纯c语言版" class="sidebar-link">4.2.纯C语言版</a></li></ul></li><li><a href="/03.Software/01.DataStructureAndAlgorithm/Part01.OJ%E5%A4%9A%E7%BB%84%E8%BE%93%E5%85%A5%E8%BE%93%E5%87%BA.html#参考资料" class="sidebar-link">参考资料</a><ul class="sidebar-sub-headers"></ul></li></ul></div></li></ul> </div> <div class="page"> <div class="content"><h1 id="oj多组和单组输入输出"><a href="#oj多组和单组输入输出" class="header-anchor">#</a> OJ多组和单组输入输出</h1> <h2 id="📑-目录"><a href="#📑-目录" class="header-anchor">#</a> 📑 目录</h2> <p>[TOC]</p> <h2 id="_01-oj中多组和单组输入输出"><a href="#_01-oj中多组和单组输入输出" class="header-anchor">#</a> 01.OJ中<code>多组</code>和<code>单组</code>输入输出</h2> <h3 id="_1-1-循环i-o处理faq"><a href="#_1-1-循环i-o处理faq" class="header-anchor">#</a> 1.1.循环I/O处理<code>FAQ</code></h3> <ul><li>多组输入和输出的做法在ACM和各大OJ也是很常见这些，现在企业招聘使用的一些平台很多也是支持这样的。</li> <li><strong>碎碎念</strong>：笔者以前的时候，第一次接触接触这种输入输出的时候，很是不适应，但是后来，看到下面的一段文字才深刻理解了，单组输入输出和多组输入输出的联系。后来我就没有以前那么纠结，每次做题都想这题到底有没有按暗示我多组输入输出。后来我想通了之后的做法，就是，能用多组输入输出的我也懒得用单组输入输出了，因为多组的方式也能AC掉单组的，但是反之不一定，原因见下面的两端文字吧：
<ul><li>1、为什么需要循环输入输出：通常来说 OJ 对于每道题里面有<code>.in</code>和<code>.out</code>文件，分别表示测试数据的输入和输出。如果某些编程题的<b>所有数据</b>都只做在<b>一个.in </b>和<b>一个.out </b>中，这样就会变成多组测试了，所以需要提交的代码中循环处理。</li> <li>2、处理方法：其实这个问题可以避免，就是编程题后台每个样例做一组对应的<code>.in</code>和<code>.out</code> 文件，这样就变成单组测试，代码就不需要循环处理，但是<strong>平时练习的题目质量不一</strong>，这个问题都会出现。</li> <li>解决方案：代码里面循环处理了即使是单组测试也会完全没问题，所以为了偷懒，可以<font style="background:yellow;"><b>全写成循环处理</b></font>。</li></ul></li></ul> <p>在线评测系统，你的程序的输入和输出是相互独立的（也就是说，一个在.in文件，输出会重定向到另一个.out文件），因此，每当处理完一组测试数据，就应当按题目要求进行相应的输出，而不必将所有结果存储起来一起输出。</p> <h3 id="_1-2-常见语法"><a href="#_1-2-常见语法" class="header-anchor">#</a> 1.2.常见语法</h3> <div class="language-c line-numbers-mode"><pre class="language-c"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;stdio.h&gt;</span></span>
<span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">int</span> a<span class="token punctuation">,</span>b<span class="token punctuation">;</span>
    <span class="token keyword">while</span><span class="token punctuation">(</span><span class="token function">scanf</span><span class="token punctuation">(</span><span class="token string">&quot;%d%d&quot;</span><span class="token punctuation">,</span><span class="token operator">&amp;</span>a<span class="token punctuation">,</span> <span class="token operator">&amp;</span>b<span class="token punctuation">)</span> <span class="token operator">!=</span> <span class="token constant">EOF</span><span class="token punctuation">)</span>	<span class="token comment">//注意while处理多个case</span>
        <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;%d\n&quot;</span><span class="token punctuation">,</span>a<span class="token operator">+</span>b<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><p>但是我本人，还喜欢这种方式</p> <div class="language-c line-numbers-mode"><pre class="language-c"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;stdio.h&gt;</span></span>
<span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">int</span> a<span class="token punctuation">,</span>b<span class="token punctuation">;</span>
    <span class="token keyword">while</span><span class="token punctuation">(</span><span class="token operator">~</span><span class="token function">scanf</span><span class="token punctuation">(</span><span class="token string">&quot;%d%d&quot;</span><span class="token punctuation">,</span><span class="token operator">&amp;</span>a<span class="token punctuation">,</span><span class="token operator">&amp;</span>b<span class="token punctuation">)</span><span class="token punctuation">)</span>	<span class="token comment">//注意while处理多个case</span>
        <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;%d\n&quot;</span><span class="token punctuation">,</span>a<span class="token operator">+</span>b<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><p>解释：<code>while(~scanf(&quot;%d%d&quot;,&amp;a,&amp;b))</code>和<code>while(scanf(&quot;%d%d&quot;,&amp;a, &amp;b) != EOF)</code>是等效的
~是按位取反，scanf的返回值是输入值的个数，如果没有输入值就是返回-1
而我们知道-1的补码表示就是全1，按位取反显然就是0</p> <p>//特别的，还有在多组输入同时还要求a或者b不为0的</p> <div class="language-c line-numbers-mode"><pre class="language-c"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;cstdio&gt;</span></span>
<span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
	<span class="token keyword">int</span> a<span class="token punctuation">,</span>b<span class="token punctuation">;</span>
	<span class="token keyword">while</span><span class="token punctuation">(</span><span class="token function">scanf</span><span class="token punctuation">(</span><span class="token string">&quot;%d%d&quot;</span><span class="token punctuation">,</span><span class="token operator">&amp;</span>a<span class="token punctuation">,</span><span class="token operator">&amp;</span>b<span class="token punctuation">)</span><span class="token operator">!=</span><span class="token constant">EOF</span><span class="token operator">&amp;&amp;</span><span class="token punctuation">(</span>a<span class="token operator">!=</span><span class="token number">0</span><span class="token operator">||</span>b<span class="token operator">!=</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
	<span class="token punctuation">{</span>
		<span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;%d\n&quot;</span><span class="token punctuation">,</span>a<span class="token operator">+</span>b<span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
	<span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;iostream&gt;</span></span>
<span class="token keyword">using</span> <span class="token keyword">namespace</span> std<span class="token punctuation">;</span>
<span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">int</span> a<span class="token punctuation">,</span>b<span class="token punctuation">;</span>
    <span class="token keyword">while</span><span class="token punctuation">(</span>cin <span class="token operator">&gt;&gt;</span> a <span class="token operator">&gt;&gt;</span> b<span class="token punctuation">)</span><span class="token comment">//注意while处理多个case</span>
        cout <span class="token operator">&lt;&lt;</span> a<span class="token operator">+</span>b <span class="token operator">&lt;&lt;</span> endl<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><h3 id="_1-3-笔试题技巧✔️"><a href="#_1-3-笔试题技巧✔️" class="header-anchor">#</a> 1.3.笔试题技巧✔️</h3> <ul><li>做了好多牛客类型的，发现有的题目可能就是需要用『找规律』的思想去做。</li> <li>不要老是想着暴力，太限制自己的思考了</li></ul> <h3 id="_1-4-多组输入输出的坑"><a href="#_1-4-多组输入输出的坑" class="header-anchor">#</a> 1.4.多组输入输出的坑</h3> <ul><li>如果测试数据是多组的，但是恰巧你代码里面需要一些标记数组，比如map,set啥的。</li> <li>在循环内一定的记得清空，不然可能会产生：前面的测试样例影响了后续数据的答案这种情况。</li></ul> <h3 id="_1-5-关于输出格式的坑"><a href="#_1-5-关于输出格式的坑" class="header-anchor">#</a> 1.5.关于输出格式的坑</h3> <ul><li>1、行末空格：比如，我输出需要打印多个数需要使用空格分隔的时候，我们循环使用<code>printf(&quot;%d &quot;,x)</code>这种会很方便，但是这样会导致行末多1个空格，后台系统会严格比对你的输出和.out文件，这样也会被判错误</li> <li>2、换行问题：<strong>对于每个样例，建议输出完全之后都换行一下</strong>。对于一些题目，可能就是不换行就导致了后面输入数据错位，那就肯定不可能过了</li></ul> <h2 id="_02-『多组输入输出』oj使用经验"><a href="#_02-『多组输入输出』oj使用经验" class="header-anchor">#</a> 02.『多组输入输出』OJ使用经验</h2> <h3 id="_2-1-如何搞定超时？估计需要的算法时间复杂度✔️"><a href="#_2-1-如何搞定超时？估计需要的算法时间复杂度✔️" class="header-anchor">#</a> 2.1.如何搞定<code>超时</code>？估计需要的算法时间复杂度✔️</h3> <blockquote><p>方法1：</p></blockquote> <ul><li>Q：如何知道自己代码是否太慢了，超时？
背景：实际编码的时候，大家其实都不会去马上分析时间复杂度，可能是先写完再看会不会超时，那就产生上面的问题。</li> <li>A：可以用大的边界的数据，最耗时的那种
用1 1000000000000，本地，自我运行了一次，发现，2秒没出来，很显然超时，毕竟比赛的也就1-2秒，测一下也不掉肉</li></ul> <blockquote><p>方法2技巧：<font style="background:yellow;">看需要处理的数据的大小——判断能不能使用暴力</font></p></blockquote> <ul><li>关于『时间复杂度』分析</li> <li>通常来说：以『C/C++为标准』的，一般的系统『<code>1s</code>』能够跑的算法量级是『不足10<sup>8</sup>』的，所以做题的时候评估算效率很重要</li> <li>直接判断你的做法能不能通过（也就是能不能暴力去解决），其他语言自己乘个时间倍数</li> <li>一般情况下，对于大部分OJ,可以假设1秒钟可以完成10^8的计算量，那么对于一个规模为10^3的数据，你可以采取复杂度为O(N^2)的算法，但当规模上升到10^5时，采取O(N^2)的算法就会得到一个TLE（超时）的结果。</li></ul> <blockquote><p>重要经验：<font style="background:yellow;">重要经验</font></p></blockquote> <ul><li>比如题目中n=10<sup>5</sup></li> <li>那么，我们就可以很敏感的知道我们的算法需要一个O(n)或者O( nlog(n) )</li> <li>『平方复杂度直接ByeBye』</li></ul> <div class="language-txt line-numbers-mode"><pre class="language-text"><code>吐槽：这一点，在最开始学习计算机的时候没有理解那么清晰，现在很清楚了！！
上面的经验是很宝贵的！！！
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>例题：</p> <p><img src="https://cdn.jsdelivr.net/gh/HACV/picture/img/01.OJ%E6%97%B6%E9%97%B4%E5%A4%8D%E6%9D%82%E5%BA%A6.png" alt="01.OJ时间复杂度"></p> <p><img src="https://cdn.jsdelivr.net/gh/HACV/picture/img/02.OJ%E6%97%B6%E9%97%B4%E5%A4%8D%E6%9D%82%E5%BA%A6.png" alt="02.OJ时间复杂度"></p> <ul><li>如上：</li></ul> <div class="language-txt line-numbers-mode"><pre class="language-text"><code>数据是5次方，你如果循环2层，也就是平方复杂度，那直接凉凉，但是暴力有分。。。实在走投无路可以弄
- 写暴力不一定得满分，但是可能有50%啥的，，比如上题在『2021年第3次模拟』过的样例7/12，获得分数50%

PS:我当时做该题，就是考虑到了无法直接暴力，所以使用了其他算法：2个前缀和
- 1、前缀和统计&lt;=当前数字的有多少个元素
- 2、前缀和，统计&lt;=当前数字的元素和
然后，将整体求和，然后利用上面将数字分割为Less和Up级

其他算法：下标和元素绑定在一起排序
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><h3 id="_2-2-常见边界数据"><a href="#_2-2-常见边界数据" class="header-anchor">#</a> 2.2.常见边界数据</h3> <ul><li>1、数据全相同</li> <li>2、全0</li> <li>3、元素无</li> <li>4、空指针</li> <li>5、奇/偶测试数据</li></ul> <h3 id="_2-3-什么叫特判『special-judge』✔️"><a href="#_2-3-什么叫特判『special-judge』✔️" class="header-anchor">#</a> 2.3.什么叫特判『Special judge』✔️</h3> <ul><li>大概意思是：题目同样的样例，你的输出可能和题目不一样也没所谓</li> <li>也就是你输出的结果可以和题目中样例输出结果不一样，但是是对的。</li> <li>反正答案对就行，比如某个矩阵，横竖斜和是15，答案不唯一，你只要写出一个也OK</li></ul> <blockquote><p>特判底层原理：将你的输出数据，输入去检测，而不是一般的比对</p></blockquote> <ul><li>在幻方矩阵一题中，还有那个所谓的（特殊判断）</li> <li>笔者在，2020年（即2021届秋招）腾讯笔试中遇见了</li></ul> <blockquote><p>HDOJ上的解释是：</p></blockquote> <ul><li>对于<strong>有多解</strong>的题目或者是<strong>对于浮点型答案需要另加精度判定</strong>的题目会有special judge</li> <li>即OJ判题者会另写一个程序来判定你给出的解是否可行（对于多解的题目）或者给出的解是否在规定的范围内（对于浮点型输出需要精度判定的题目）。</li></ul> <h3 id="_2-4-『多组输出输出』常见坑：防踩坑"><a href="#_2-4-『多组输出输出』常见坑：防踩坑" class="header-anchor">#</a> 2.4.『多组输出输出』常见坑：防踩坑</h3> <ul><li>1、循环输入输出：会发生一个问题(十分常见！！)，如果测试数据是多组的，但是恰巧你代码里面需要些标记数组，map，set 等，在循环内一定记得清空，不然可能会产生前面的测试样例影响了后续数据的答案。</li> <li>2、一般多组输出，记得要换行，<code>printf(&quot;%d\n&quot;,sum);</code></li> <li><code>//第一次的时候，由于没有加\n，OJ告诉我是，答案错误</code></li> <li><code>//加了\n就对了</code></li></ul> <h3 id="_2-5-『训练』牛客多组i-o"><a href="#_2-5-『训练』牛客多组i-o" class="header-anchor">#</a> 2.5.『训练』牛客多组I/O</h3> <ul><li><a href="https://ac.nowcoder.com/acm/contest/5650" target="_blank" rel="noopener noreferrer">OJ在线编程常见输入输出练习场<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul> <h3 id="_2-6-mle"><a href="#_2-6-mle" class="header-anchor">#</a> 2.6.MLE</h3> <ul><li><p><strong>Memory Limit Exceeded     (MLE)</strong> : 内存开的过大</p></li> <li><p>一般情况下，对于online judge而言静态数组可以开到K*10<sup>6</sup>大小，K在5左右。</p></li> <li><p><strong>Runtime     Error (RE)</strong> :运行出现问题，可能是以下情况：.</p></li> <li><ul><li>*<strong>ACCESS_VIOLATION*</strong> 访问越界，多数情况为数组开小了。</li> <li>*<strong>INTEGER_DIVIDE_BY_ZERO*</strong> 出现0为除数的情况。</li> <li>*<strong>STACK_OVERFLOW*</strong>      栈溢出。</li> <li>*<strong>......*</strong> Other runtime errors.</li></ul></li></ul> <h3 id="_2-7-关于cin的速度"><a href="#_2-7-关于cin的速度" class="header-anchor">#</a> 2.7.关于cin的速度</h3> <ul><li>对于大部分国内OJ而言，cin,cout在没有加一些**黑科技（其实，就是那个同步。。HACV）**之前的读入输出速度会比scanf,printf慢，建议尽量使用scanf,printf；</li></ul> <h2 id="_03-c和c-混合i-o难点辨析"><a href="#_03-c和c-混合i-o难点辨析" class="header-anchor">#</a> 03.C和C++混合I/O难点辨析</h2> <h3 id="_3-1-辨析单引号和双引号"><a href="#_3-1-辨析单引号和双引号" class="header-anchor">#</a> 3.1.辨析单引号和双引号</h3> <ul><li>单引号：<code>'3'</code>代表的是“字符”3</li> <li>双引号：<code>&quot;3&quot;</code>代表的是“字符串”3</li></ul> <blockquote><p>『字符』和『字符串』在C语言和C++中的区别和联系</p></blockquote> <ul><li>字符：
C语言和<code>C++</code>中都是用char来承载，<code>C++</code>中string类，<code>[]</code>运算符返回的也是char</li> <li>字符串：
C语言中，用字符数组来承载
<code>C++</code>中用string类来承载
为了能够将<code>C++</code>中其他STL和string类的配合到极致，我们需要非常熟悉C语言风格的字符数组和<code>C++</code>的string类的互相转化。</li></ul> <h3 id="_3-2-常见数字格式—输入输出"><a href="#_3-2-常见数字格式—输入输出" class="header-anchor">#</a> 3.2.常见数字格式—输入输出</h3> <table><thead><tr><th></th> <th>输入</th> <th>输出</th></tr></thead> <tbody><tr><td>int</td> <td>%d</td> <td>%d</td></tr> <tr><td>long long</td> <td>%lld</td> <td>%lld</td></tr> <tr><td>double</td> <td>%lf</td> <td>%lf</td></tr></tbody></table> <h3 id="_3-3-字符串输入输出"><a href="#_3-3-字符串输入输出" class="header-anchor">#</a> 3.3.字符串输入输出</h3> <p>注意：</p> <p>字符串是个逻辑概念</p> <ul><li>纯C语言中，用字符数组来承载它，也就是我们所说的具体实现</li> <li>纯C++写法中，用string来承载它。PS：string底层封装了字符数组，但是比较复杂，初学C++不需要深究，不看源代码，无法理解。</li></ul> <p>我们只考虑，C语言的输入输出。</p> <p>C++的string，请用cin啥的。</p> <table><thead><tr><th></th> <th>输入</th> <th>输出</th></tr></thead> <tbody><tr><td>字符串</td> <td>%s</td> <td>%s</td></tr> <tr><td>字符</td> <td>%c</td> <td>%c</td></tr></tbody></table> <p>字符和字符串的差别，在第1讲讲了。难点在字符串用“字符数组承载”</p> <h4 id="_1、用scanf"><a href="#_1、用scanf" class="header-anchor">#</a> 1、用scanf</h4> <p>scanf的%s</p> <p>输入：是识别到<code>' '</code>（空格）或者<code>'\n'</code>（换行）就不要了，然后在扫描进的后面自动加上<code>'\0'</code></p> <p>输出：是识别到<code>'\0'</code>就输出完毕</p> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;bits/stdc++.h&gt;</span></span>
<span class="token keyword">using</span> <span class="token keyword">namespace</span> std<span class="token punctuation">;</span>

<span class="token keyword">static</span> <span class="token keyword">const</span> <span class="token keyword">int</span> maxn<span class="token operator">=</span><span class="token number">1e5</span><span class="token operator">+</span><span class="token number">5</span><span class="token punctuation">;</span>
<span class="token keyword">int</span> solve<span class="token punctuation">[</span>maxn<span class="token punctuation">]</span><span class="token punctuation">;</span>

<span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
    <span class="token function">scanf</span><span class="token punctuation">(</span><span class="token string">&quot;%s&quot;</span><span class="token punctuation">,</span>solve<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">//第1组测试123 24343</span>
    <span class="token comment">//第2组测试23134131</span>
    
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;%s&quot;</span><span class="token punctuation">,</span>solve<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div><blockquote><p>scanf的%s是以 空白符（包括空格）来进行截断的！！
注意，在读入n之后，要使用getchar来接收后面的换行符，否则会使得for循环内的gets读入这个换行符，导致第1个字符串读取错误。</p></blockquote> <h4 id="_2、用gets"><a href="#_2、用gets" class="header-anchor">#</a> 2、用gets</h4> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code><span class="token keyword">char</span> test<span class="token punctuation">[</span><span class="token number">105</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
<span class="token keyword">int</span> i<span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">;</span>
<span class="token keyword">while</span><span class="token punctuation">(</span><span class="token constant">NULL</span><span class="token operator">!=</span><span class="token function">gets</span><span class="token punctuation">(</span>test<span class="token punctuation">)</span><span class="token punctuation">)</span> 
<span class="token punctuation">{</span>
    <span class="token operator">++</span>i<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><ul><li>PAT中C语言编译器允许用</li> <li>PAT中C++编译器<strong>禁止</strong>这个用法！（由于可以利用该函数进行『缓冲区溢出攻击』）</li> <li>牛客上C++编译器<strong>禁止</strong>这个用法！（由于可以利用该函数进行『缓冲区溢出攻击』）</li></ul> <p>gets输入一行，无论中间会不会有空格</p> <p><strong>它识别到'\n'就不要了</strong></p> <blockquote><p>Tips：由于，gets这个函数可以进行“缓冲区溢出”攻击，在很多平台开始禁用！</p> <ul><li>牛客网禁用</li> <li>PTA禁用</li></ul></blockquote> <p><strong>PTA和牛客对比注意：</strong></p> <p>1.PAT上数据比牛客上严格<br>
2.PAT上2020年有一些题目的边界数据的增加，有的教程上代码无法AC了</p> <h3 id="_3-4-用2种方法解决gets被禁用✔️"><a href="#_3-4-用2种方法解决gets被禁用✔️" class="header-anchor">#</a> 3.4.用2种方法解决<code>gets被禁用</code>✔️</h3> <h3 id="问题引入：pat编译器上的坑"><a href="#问题引入：pat编译器上的坑" class="header-anchor">#</a> 问题引入：PAT编译器上的坑</h3> <ul><li>PAT的这两个<code>C++</code>编译器(<code>C++ gcc6.5.0</code>和<code>C++ clang++ 6.0.1</code>）都不支持<code>gets()</code></li></ul> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code><span class="token comment">//要是你的C++代码中出现了，就会导致（似乎原因是什么不安全...）    </span>
a<span class="token punctuation">.</span>cpp<span class="token operator">:</span> In function ‘<span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span>’<span class="token operator">:</span>
a<span class="token punctuation">.</span>cpp<span class="token operator">:</span><span class="token number">12</span><span class="token operator">:</span><span class="token number">11</span><span class="token operator">:</span> error<span class="token operator">:</span> ‘gets’ was <span class="token operator">not</span> declared in <span class="token keyword">this</span> scope
  <span class="token function">gets</span><span class="token punctuation">(</span>str1<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><ul><li>『注意』：<font style="background:yellow;">PAT上面的C语言编译器支持<code>gets()</code>（可以用C语言编译器）</font>，如果你不想用<code>C++</code>的STL的话</li></ul> <h3 id="方案1：getline-cin-first-✔️"><a href="#方案1：getline-cin-first-✔️" class="header-anchor">#</a> 方案1：<code>getline(cin, first);</code>✔️</h3> <ul><li>我最常用的！</li></ul> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code>string first<span class="token punctuation">;</span>
<span class="token keyword">while</span><span class="token punctuation">(</span> <span class="token function">getline</span><span class="token punctuation">(</span>cin<span class="token punctuation">,</span> first<span class="token punctuation">)</span> <span class="token punctuation">)</span>
<span class="token punctuation">{</span>
    cout<span class="token operator">&lt;&lt;</span>first<span class="token operator">&lt;&lt;</span>endl<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><ul><li>如我写的这个<a href="https://hacv.gitee.io/coding/#/./01.PAT/02.%E7%94%B2%E7%BA%A7C++11%E7%89%88%E6%9C%AC?id=a1071-speech-patterns" target="_blank" rel="noopener noreferrer">题解的代码<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul> <h3 id="方案2：cin-getline✔️"><a href="#方案2：cin-getline✔️" class="header-anchor">#</a> 方案2：<code>cin.getline</code>✔️</h3> <ul><li>使用 <strong>iostream</strong>库中的<code>cin.getline</code>函数代替<code>gets</code></li> <li>『使用比方法1麻烦点』</li></ul> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code><span class="token comment">/* 读入一行（可含空格），直到换行符结束
 * 将其前num-1个字符存入数组a中并以字符c结尾 */</span>
cin<span class="token punctuation">.</span><span class="token function">getline</span><span class="token punctuation">(</span>a<span class="token punctuation">,</span> num<span class="token punctuation">,</span> c<span class="token punctuation">)</span><span class="token punctuation">;</span>
解决方式：
使用 iostream 库中的cin<span class="token punctuation">.</span>getline函数代替gets
tips：
<span class="token number">1</span>、也可以不传入第三个参数c，则默认 <span class="token string">'\0'</span> 结尾
<span class="token number">2</span>、若num大于所读入的字符数，则直接存入整行字符串，再在末尾加入字符c结尾
    
比如
    cin<span class="token punctuation">.</span><span class="token function">getline</span><span class="token punctuation">(</span>ch2<span class="token punctuation">,</span><span class="token number">6</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//在不遇到结束符的情况下，最多可接收6-1=5个字符到ch2中 </span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><ul><li>演示如下：</li></ul> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code><span class="token keyword">char</span> solve<span class="token punctuation">[</span><span class="token number">20</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
<span class="token comment">//注意，下面我们用的是20，但是实际上获得的是19个，因为最后那个被识别到的'\0'也要识别进去</span>
<span class="token comment">//然后，</span>
<span class="token keyword">while</span><span class="token punctuation">(</span> cin<span class="token punctuation">.</span><span class="token function">getline</span><span class="token punctuation">(</span> solve<span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">)</span> <span class="token punctuation">)</span>
<span class="token punctuation">{</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;%s\n&quot;</span><span class="token punctuation">,</span>solve<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;Ok\n&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><h2 id="_04-oj多组输入输出『分语言』"><a href="#_04-oj多组输入输出『分语言』" class="header-anchor">#</a> 04.OJ多组输入输出『分语言』</h2> <h3 id="_4-1-纯c-语言版（不准用c语言版本）"><a href="#_4-1-纯c-语言版（不准用c语言版本）" class="header-anchor">#</a> 4.1.纯C++语言版（不准用C语言版本）</h3> <ul><li>为了能够熟练的使用<code>C++</code>的STL</li> <li>由于自己熟练C语言的字符数组，思维方式快成纯C语言的了，但是这些很影响刷OJ做题的速度。</li> <li>所以，打算，使用<code>C++</code>中的<code>String</code>代替字符数组</li> <li>弃用字符数组。</li></ul> <p>原因</p> <div class="language-txt line-numbers-mode"><pre class="language-text"><code>比如字符查找，我就可以懒得写了
字符匹配，也懒得写
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><ul><li><strong>1、整型数据</strong></li></ul> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;iostream&gt;</span></span>
<span class="token keyword">using</span> <span class="token keyword">namespace</span> std<span class="token punctuation">;</span>

<span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
	<span class="token keyword">int</span> a<span class="token punctuation">,</span>b<span class="token punctuation">;</span>
	
	<span class="token keyword">while</span><span class="token punctuation">(</span>cin<span class="token operator">&gt;&gt;</span>a<span class="token operator">&gt;&gt;</span>b<span class="token punctuation">)</span>
	<span class="token punctuation">{</span>
		cout<span class="token operator">&lt;&lt;</span>a<span class="token operator">+</span>b<span class="token operator">&lt;&lt;</span>endl<span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
	<span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span> 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br></div></div><p><strong>严格的</strong></p> <p>这样的格式</p> <div class="language-txt line-numbers-mode"><pre class="language-text"><code>3,6
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>//cin.get()使用比较难讲，不要赖用</li></ul> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;iostream&gt;</span></span>
<span class="token keyword">using</span> <span class="token keyword">namespace</span> std<span class="token punctuation">;</span>

<span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
	<span class="token keyword">int</span> a<span class="token punctuation">,</span>b<span class="token punctuation">;</span>
	<span class="token keyword">char</span> c<span class="token punctuation">;</span>
	<span class="token keyword">while</span><span class="token punctuation">(</span><span class="token punctuation">(</span>cin<span class="token operator">&gt;&gt;</span>a<span class="token punctuation">)</span><span class="token operator">&amp;&amp;</span><span class="token punctuation">(</span>c<span class="token operator">=</span>cin<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token operator">&amp;&amp;</span><span class="token punctuation">(</span>cin<span class="token operator">&gt;&gt;</span>b<span class="token punctuation">)</span><span class="token punctuation">)</span>
	<span class="token punctuation">{</span>
		cout<span class="token operator">&lt;&lt;</span>a<span class="token operator">+</span>b<span class="token operator">&lt;&lt;</span>endl<span class="token punctuation">;</span>
        cout<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span>c<span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
	<span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span> 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br></div></div><ul><li><strong>2、字符数组</strong>（C++中用string类——自己不准自己用字符数组）</li></ul> <p>注意，这种输入，下面这样的数据，注意也用这组数据测试3）</p> <div class="language-txt line-numbers-mode"><pre class="language-text"><code>asdad asdsa
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;iostream&gt;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;string&gt;</span> </span>
<span class="token keyword">using</span> <span class="token keyword">namespace</span> std<span class="token punctuation">;</span>

<span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
	string str<span class="token punctuation">;</span>
	<span class="token keyword">while</span><span class="token punctuation">(</span>cin<span class="token operator">&gt;&gt;</span>str<span class="token punctuation">)</span>
	<span class="token punctuation">{</span>
		cout<span class="token operator">&lt;&lt;</span>str<span class="token operator">&lt;&lt;</span>endl<span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
	
	<span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span> 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br></div></div><ul><li><strong>3、字符数组</strong>（C++中用string类）两个-用空格分开</li></ul> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;iostream&gt;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;string&gt;</span> </span>
<span class="token keyword">using</span> <span class="token keyword">namespace</span> std<span class="token punctuation">;</span>

<span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
	string one<span class="token punctuation">;</span>
	string two<span class="token punctuation">;</span>
	<span class="token keyword">while</span><span class="token punctuation">(</span>cin<span class="token operator">&gt;&gt;</span>one<span class="token operator">&gt;&gt;</span>two<span class="token punctuation">)</span>
	<span class="token punctuation">{</span>
		cout<span class="token operator">&lt;&lt;</span>one<span class="token operator">&lt;&lt;</span>endl<span class="token punctuation">;</span>
		cout<span class="token operator">&lt;&lt;</span>two<span class="token operator">&lt;&lt;</span>endl<span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
	
	<span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span> 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br></div></div><ul><li><strong>4、整行字符(string)，包括空格</strong>『学习记忆』</li></ul> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;iostream&gt;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;string&gt;</span> </span>
<span class="token keyword">using</span> <span class="token keyword">namespace</span> std<span class="token punctuation">;</span>

<span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
	string one<span class="token punctuation">;</span>
	string two<span class="token punctuation">;</span>
	<span class="token comment">//未考查下面这种多组输入 </span>
	<span class="token keyword">while</span><span class="token punctuation">(</span><span class="token function">getline</span><span class="token punctuation">(</span>cin<span class="token punctuation">,</span>one<span class="token punctuation">)</span><span class="token punctuation">)</span>
	<span class="token punctuation">{</span>
		cout<span class="token operator">&lt;&lt;</span>one<span class="token operator">&lt;&lt;</span>endl<span class="token punctuation">;</span>
		
	<span class="token punctuation">}</span>
	
	<span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span> 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br></div></div><h3 id="_4-2-纯c语言版"><a href="#_4-2-纯c语言版" class="header-anchor">#</a> 4.2.<code>纯C语言</code>版</h3> <ul><li><p>0、单个字符</p></li> <li><p><strong>1、整型数据</strong></p></li></ul> <div class="language-c line-numbers-mode"><pre class="language-c"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;stdio.h&gt;</span></span>

<span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
	<span class="token keyword">long</span> <span class="token keyword">long</span> <span class="token keyword">int</span> a<span class="token punctuation">,</span>b<span class="token punctuation">;</span>
	<span class="token keyword">while</span><span class="token punctuation">(</span><span class="token operator">~</span><span class="token function">scanf</span><span class="token punctuation">(</span><span class="token string">&quot;%lld%lld&quot;</span><span class="token punctuation">,</span><span class="token operator">&amp;</span>a<span class="token punctuation">,</span><span class="token operator">&amp;</span>b<span class="token punctuation">)</span><span class="token punctuation">)</span> 
	<span class="token punctuation">{</span>
		<span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;%lld\n&quot;</span><span class="token punctuation">,</span>a<span class="token operator">+</span>b<span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
	<span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><ul><li><strong>2、字符数组</strong></li></ul> <div class="language-c line-numbers-mode"><pre class="language-c"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;stdio.h&gt;</span></span>

<span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
	<span class="token keyword">char</span> test<span class="token punctuation">[</span><span class="token number">100</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
	<span class="token keyword">while</span><span class="token punctuation">(</span> <span class="token operator">~</span><span class="token function">scanf</span><span class="token punctuation">(</span><span class="token string">&quot;%s&quot;</span><span class="token punctuation">,</span>test<span class="token punctuation">)</span> <span class="token punctuation">)</span> 
	<span class="token punctuation">{</span>
		<span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;%s\n&quot;</span><span class="token punctuation">,</span>test<span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
	<span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><ul><li><strong>3、字符数组两个-用空格分开</strong></li></ul> <div class="language-txt line-numbers-mode"><pre class="language-text"><code>aa ss
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><div class="language-c line-numbers-mode"><pre class="language-c"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;stdio.h&gt;</span></span>

<span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
	<span class="token keyword">char</span> one<span class="token punctuation">[</span><span class="token number">100</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
	<span class="token keyword">char</span> two<span class="token punctuation">[</span><span class="token number">100</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
	
	<span class="token keyword">while</span><span class="token punctuation">(</span><span class="token operator">~</span><span class="token function">scanf</span><span class="token punctuation">(</span><span class="token string">&quot;%s%s&quot;</span><span class="token punctuation">,</span>one<span class="token punctuation">,</span>two<span class="token punctuation">)</span><span class="token punctuation">)</span> 
	<span class="token punctuation">{</span>
		<span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;%s 中间加上我 %s\n&quot;</span><span class="token punctuation">,</span>one<span class="token punctuation">,</span>two<span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
	<span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br></div></div><ul><li><strong>4、整行字符，包括空格</strong></li></ul> <div class="language-c line-numbers-mode"><pre class="language-c"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;stdio.h&gt;</span></span>

<span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
	<span class="token keyword">char</span> test<span class="token punctuation">[</span><span class="token number">100</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
	
	<span class="token keyword">while</span><span class="token punctuation">(</span><span class="token constant">NULL</span><span class="token operator">!=</span><span class="token function">gets</span><span class="token punctuation">(</span>test<span class="token punctuation">)</span><span class="token punctuation">)</span> 
	<span class="token punctuation">{</span>
		<span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;%s\n&quot;</span><span class="token punctuation">,</span>test<span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
	<span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><h2 id="参考资料"><a href="#参考资料" class="header-anchor">#</a> 参考资料</h2> <ul><li><a href="https://www.cnblogs.com/luyi14/p/4381508.html" target="_blank" rel="noopener noreferrer">acm比赛刷题小技巧<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li> <li>为何Acmer喜欢将<a href="https://blog.csdn.net/Dream_Weave/article/details/80048630" target="_blank" rel="noopener noreferrer">INF设置<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a>为0x3f3f3f3f？</li></ul></div> <div class="page-edit"><!----> <!----></div> <!----> </div> <!----></div></div>
    <script src="/assets/js/app.c70e21ad.js" defer></script><script src="/assets/js/56.62ac9b92.js" defer></script>
  </body>
</html>
